<template>
  <div>
    <el-table
      ref="formLayout"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      row-key="layoutId"
      border
      stripe
      fit
      highlight-current-row
      @row-click="handleRow"
      >
      <el-table-column prop="layoutName" label="布局名称" min-width="150" align="center"></el-table-column>
      <el-table-column prop="layoutType" label="类型" width="150" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.layoutType | layoutTypeFilter }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getListByTableId } from '@/api/workflow/form/layout'
import enums from '@/views/workflow/utils/enum'
export default {
  props: ['tableId'],
  filters: {
    layoutTypeFilter(type) {
      return enums.TAB_DEF[type]
    }
  },
  data() {
    return {
      list: [],
      listLoading: false
    }
  },
  watch: {
    tableId(val) {
      this.fetchData()
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    setCurrent(row) {
      this.$refs.formLayout.setCurrentRow(row);
    },
    fetchData() {
      if (!this.tableId) return
      this.listLoading = true
      getListByTableId(this.tableId).then(response => {
        this.list = response.data
        this.listLoading = false
      })
    },
    handleRow(row) {
      this.$emit('callbackFormLayout', row)
    }
  }
}
</script>
